<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>集合</title>
	</head>
	<body>
		<script>
			let s = new Set(['A','B','c','D','a','A']);
			s.add('w');
			console.log(s,typeof s);
			s.delete('a');
			console.log(s);
			console.log(s.has('C'));
			// s.clear();
			// console.log(s);
			for(let v of s) {
				console.log(v);
			}
			let arr = [1,2,3,4,5,4,3,2,1];
			// 1、数组去重
			let r1 = [...new Set(arr)]
			console.log(r1);
			// 2、交集
			let arr2 = [4,5,6,5,6];
			let r2 = [...new Set(arr)].filter(item => {
				let s2 = new Set(arr2);
				return s2.has(item);
			});
			console.log(r2);
			// 3、并集
			let union = [...new Set([...arr,arr2])];
			console.log(union);
			// 4、差集
			let diff = [...new Set(arr)].filter(item => !(new Set(arr2)).has(item));
			console.log(diff);
		</script>
	</body>
</html>